package cc.catface.order;

import brave.sampler.Sampler;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients//支持feign声明式服务调用组件

@EnableCircuitBreaker//将信息分享给监控中心hystrix dashboard
public class ServerOrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServerOrderApplication.class, args);
    }

    /*ribbon配置*/
    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

    //ribbon负载均衡策略
    /*@Bean
    public IRule rule() {
        return new RandomRule();
    }*/

    /*dashboard抽样策略*/
    @Bean
    public Sampler defaultSampler() {
        return Sampler.ALWAYS_SAMPLE;//持续抽样
    }
}
